using System;
using System.Collections.Generic;
using System.Text;

namespace ghostDBscript.Engine.Commands
{
    public class TableCreate : ICommand, IHasChildren
    {
        private string _name;
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        private List<ICommand> _children = new List<ICommand>();
        public List<ICommand> Children
        {
            get { return _children; }
            set { _children = value; }
        }

        public TableCreate(string name)
        {
            _name = name;
            ColumnAdd column = ColumnAdd.GetIDColumn();
            _children.Add(column);
        }
	
        public string ToCommandText()
        {
            StringBuilder builda = new StringBuilder();

            builda.AppendLine("CREATE TABLE [" + _name + "]");
            builda.AppendLine("(");

            for (int i = 0; i < _children.Count; i++)
            {
                if (i != _children.Count-1)
                    builda.AppendLine(_children[i].ToCommandText() + ",");
                else
                    builda.AppendLine(_children[i].ToCommandText());
            }
            builda.Append(");");
            return builda.ToString();
        }

        public bool IsValid()
        {
            if (_name == null || _name.Length < 1)
                return false;
            else
                return true;
        }
    }
}
